package cool.mylog.mylog2end.mapper;

import cool.mylog.mylog2end.bean.Log;
import cool.mylog.mylog2end.bean.Relation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RelationMapper {

    /**
     * 通过用户id获取全部人脉
     *
     * @param userid 用户id
     * @return Relation对象列表
     */
    @Select("SELECT * FROM relation WHERE userid=#{id}")
    @ResultMap("relationMap")
    List<Relation> getRelationsByUserId(Long userid);

//    @Select("select * from relation where create_user_id=#{userId}")
//    List<Relation> getRelation(int userId);
//

    /**
     * 插入新人员
     * @param relation
     * @return
     */
    Integer insertRelation(Relation relation);

    /**
     * 编辑人员
     * @param relation Relation对象
     * @return 受影响的行数
     */
    Integer updateRelation(Relation relation);

    /**
     * 删除relation
     * @param id 删除的id
     * @param userid 删除的relation的创建者
     * @return 删除的条数
     */
    @Delete("DELETE FROM relation WHERE id=#{id} AND userid=#{userid}")
    Integer deleteRelation(Long id, Long userid);
}
